package au.com.handsunited.service.impl;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import au.com.handsunited.dao.SkillDAO;
import au.com.handsunited.model.skill.Skill;
import au.com.handsunited.service.SkillService;

/**
 * @author arunda
 *
 */
public class SkillServiceImpl implements SkillService {


	private final SkillDAO skillDAO;

	private static Logger logger = LoggerFactory.getLogger(SkillServiceImpl.class);

	/**
	 * @param skillDAO
	 */
	public SkillServiceImpl(SkillDAO skillDAO) {
		super();
		this.skillDAO = skillDAO;
	}

	/**
	 * @see au.com.handsunited.service.SkillService#createSkill(au.com.handsunited.model.skill.Skill)
	 */
	@Override
	public Skill createSkill(Skill skill) {
		return skillDAO.create(skill);
	}

	/**
	 * @see au.com.handsunited.service.SkillService#deleteSkill(au.com.handsunited.model.skill.Skill)
	 */
	@Override
	public void deleteSkill(Skill skill) {
		skillDAO.delete(skill);
	}

	/**
	 * @see au.com.handsunited.service.SkillService#getAllSkills()
	 */
	@Override
	public List<Skill> getAllSkills() {
		return skillDAO.getAllSkills();
	}

	/**
	 * @see au.com.handsunited.service.SkillService#getSkill(java.lang.Long)
	 */
	@Override
	public Skill getSkill(Long id) {
		return skillDAO.read(id);
	}

	/**
	 * @see au.com.handsunited.service.SkillService#getSkill(java.lang.String)
	 */
	@Override
	public Skill getSkill(String id) {
		if (StringUtils.isNotBlank(id)) {
			return getSkill(Long.parseLong(id));
		} else {
			return null;
		}
	}

	/**
	 * @see au.com.handsunited.service.SkillService#updateSkill(au.com.handsunited.model.skill.Skill)
	 */
	@Override
	public Skill updateSkill(Skill skill) {
		return skillDAO.update(skill);
	}

	/**
	 * @see au.com.handsunited.service.SkillService#getSkillsMap()
	 */
	@Override
	public Map<Long, Skill> getSkillsMap() {
		Map<Long, Skill> skillsMap = new TreeMap<Long, Skill>();
		for (Skill skill : getAllSkills()) {
			skillsMap.put(skill.getId(), skill);
		}
		return skillsMap;
	}

}
